<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>提现页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui-v2.6.3/css/layui.css}" href="../../static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" href="../../static/css/public.css" media="all">
    <link rel="stylesheet" th:href="@{/js/lay-module/step-lay/step.css}" href="../../static/js/lay-module/step-lay/step.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-body" style="padding-top: 40px;">
                    <div class="layui-carousel" id="stepForm" lay-filter="stepForm" style="margin: 0 auto;">
                        <div carousel-item>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">选择银行卡:</label>
                                        <div class="layui-input-block">
                                            <select name="cardNumber" lay-verify="required" lay-filter="card" id="card">
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">提现金额:</label>
                                        <div class="layui-input-block">
                                            <input type="number" placeholder="请填写充值金额" value="" name="money" class="layui-input" lay-verify="number" required>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" lay-submit lay-filter="formStep">
                                                &emsp;下一步&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">支付密码:</label>
                                        <div class="layui-input-block">
                                            <input class="layui-input" name="payPassword"  maxlength="6" type="number">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button type="button" class="layui-btn layui-btn-primary pre">上一步</button>
                                            <button class="layui-btn" lay-submit lay-filter="formStep2">
                                                &emsp;确认提款&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <div style="text-align: center;margin-top: 90px;">
                                    <i class="layui-icon layui-circle"
                                       style="color: white;font-size:30px;font-weight:bold;background: #52C41A;padding: 20px;line-height: 80px;">&#xe605;</i>
                                    <div style="font-size: 24px;color: #333;font-weight: 500;margin-top: 30px;">
                                        提现成功
                                    </div>
                                    <div style="font-size: 14px;color: #666;margin-top: 20px;">预计两小时到账</div>
                                </div>
                                <div style="text-align: center;margin-top: 50px;">
                                    <button class="layui-btn next">再入一笔</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<script th:src="@{/lib/layui-v2.6.3/layui.js}" src="../../static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script th:src="@{/js/lay-config.js?v=1.0.4}" src="../../static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use([ 'form', 'step','layer'], function () {
        var $ = layui.$,
            form = layui.form,
            layer = layui.layer,
            step = layui.step;


        $.ajax({
            type:"get",
            url:"/ecis/binding-card/getCardSet",
            data:{userId:localStorage.getItem("id")},
            dataType:"json",
            success:function (res) {
                if (res.code == 200){
                    // 添加银行卡集合
                    let option = '<option value="">请选择银行卡</option>\n';
                    for(let item in res.data){
                        option += '<option value="'+res.data[item].id+'">'+res.data[item].id+'</option>';
                    }
                    option += '<option value="addCard">添加银行卡</option>';
                    $("#card").html(option)
                    form.render();
                }else{
                    layer.msg("未绑卡,即将跳转绑卡页面",{icon:5},function (){
                        window.location = "/page/bindingCard"
                    })
                }
            }
        })

        let _data;

        step.render({
            elem: '#stepForm',
            filter: 'stepForm',
            width: '100%', //设置容器宽度
            stepWidth: '750px',
            height: '500px',
            stepItems: [{
                title: '填写充值信息'
            }, {
                title: '输入支付密码'
            }, {
                title: '完成'
            }]
        });

        form.on("select(card)",function(data){
            if(data.value == 'addCard'){
                window.location = "/page/bindingCard"
            }
        })


        form.on('submit(formStep)', function (data) {
            _data = data.field
            step.next('#stepForm');
            return false;
        });

        form.on('submit(formStep2)', function (data) {
            if(data.field.payPassword == ""){
                layer.msg("支付密码不可空",{icon:5})
                return false
            }
            _data.payPassword = data.field.payPassword;
            _data.userId = localStorage.getItem("id");
            $.ajax({
                type:"post",
                url:"/ecis/reflect",
                data:_data,
                dataType: "json",
                success:function (res){
                    if (res.code == 200){
                        $("input[name=money]").val(null);
                        $("input[name=payPassword]").val(null)
                        step.next('#stepForm');
                    }else {
                        layer.msg(res.msg,{icon:2})
                    }
                }
            })
            return false;
        });

        $('.pre').click(function () {
            step.pre('#stepForm');
        });

        $('.next').click(function () {
            step.next('#stepForm');
        });

        form.render();

    })
</script>
</body>
</html>